﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Data.Business;
using NLBS.Data;

namespace NLBS.Views
{
    public class CategoryPresenter : Presenter<ICategoryView,ICategoryAction>
    {
        public override void OnViewLoaded()
        {
            base.OnViewLoaded();
            this.View.CatList = CategoryData.GetCategory();
        }

        public override void OnActionLoaded()
        {
            this.Action.DataDelete += new EventHandler(View_DataDelete);
            this.Action.DataSelectSingle += new EventHandler(View_DataSelectSingle);
            this.Action.DataInsert += new EventHandler(View_DataInsert);
            this.Action.DataUpdate += new EventHandler(View_DataUpdate);
            this.Action.DataMove += new EventHandler(View_DataMove);
            base.OnActionLoaded();
        }

        void View_DataMove(object sender, EventArgs e)
        {
            DbProvider.Instance().MoveCategory(this.Action.MoveCatList, this.Action.keyID);
        }

        void View_DataUpdate(object sender, EventArgs e)
        {
            CategoryData.UpdateCategory(this.Action.Entity);
        }

        void View_DataInsert(object sender, EventArgs e)
        {
            CategoryData.InsertCategory(this.Action.Entity);
        }

        void View_DataSelectSingle(object sender, EventArgs e)
        {
            this.Action.Entity = CategoryData.GetCategoryByID(this.Action.keyID);
        }

        void View_DataDelete(object sender, EventArgs e)
        {
            CategoryData.DeleteCategory(this.Action.keyID);
        }
    }
}
